home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 22 / PCPP #22.iso / Quake2 / q2source_12_11 / utils3 / qe4 / win_ent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-06  |  22.8 KB  |  1,116 lines

  1. #include "qe3.h"
  2. #include "entityw.h"
  3.  
  4. int rgIds[EntLast] = {
  5.     IDC_E_LIST,
  6.     IDC_E_COMMENT,
  7.     IDC_CHECK1,
  8.     IDC_CHECK2,
  9.     IDC_CHECK3,
  10.     IDC_CHECK4,
  11.     IDC_CHECK5,
  12.     IDC_CHECK6,
  13.     IDC_CHECK7,
  14.     IDC_CHECK8,
  15.     IDC_CHECK9,
  16.     IDC_CHECK10,
  17.     IDC_CHECK11,
  18.     IDC_CHECK12,
  19.     IDC_E_PROPS,
  20.     IDC_E_0,
  21.     IDC_E_45,
  22.     IDC_E_90,
  23.     IDC_E_135,
  24.     IDC_E_180,
  25.     IDC_E_225,
  26.     IDC_E_270,
  27.     IDC_E_315,
  28.     IDC_E_UP,
  29.     IDC_E_DOWN,
  30.     IDC_E_DELPROP,
  31.  
  32.     IDC_STATIC_KEY,
  33.     IDC_E_KEY_FIELD,
  34.     IDC_STATIC_VALUE,
  35.     IDC_E_VALUE_FIELD,
  36.  
  37.     IDC_E_COLOR
  38. };
  39.  
  40. HWND hwndEnt[EntLast];
  41.  
  42. int        inspector_mode;        // W_TEXTURE, W_ENTITY, or W_CONSOLE
  43.  
  44. qboolean    multiple_entities;
  45.  
  46. entity_t    *edit_entity;
  47.  
  48. HWND CreateTextureWindow (void);
  49.  
  50. BOOL CALLBACK EntityWndProc(
  51.     HWND hwndDlg,    // handle to dialog box
  52.     UINT uMsg,        // message
  53.     WPARAM wParam,    // first message parameter
  54.     LPARAM lParam);    // second message parameter
  55.  
  56. void SizeEntityDlg(int iWidth, int iHeight);
  57. void AddProp(void);
  58. void GetTexMods(void);
  59.  
  60.  
  61. LRESULT (CALLBACK* OldFieldWindowProc) (HWND, UINT, WPARAM, LPARAM);
  62. LRESULT (CALLBACK* OldEntityListWindowProc) (HWND, UINT, WPARAM, LPARAM);
  63.  
  64. /*
  65. =========================
  66. FieldWndProc
  67.  
  68. Just to handle tab and enter...
  69. =========================
  70. */
  71. BOOL CALLBACK FieldWndProc(
  72.     HWND hwnd,
  73.     UINT uMsg,
  74.     WPARAM wParam,
  75.     LPARAM lParam)
  76. {
  77.     switch (uMsg)
  78.     {
  79.     case WM_CHAR:
  80.         if (LOWORD(wParam) == VK_TAB)
  81.             return FALSE;
  82.         if (LOWORD(wParam) == VK_RETURN)
  83.             return FALSE;
  84.         if (LOWORD(wParam) == VK_ESCAPE)
  85.         {
  86.             SetFocus (g_qeglobals.d_hwndCamera);
  87.             return FALSE;
  88.         }
  89.         break;
  90.  
  91.     case WM_KEYDOWN:
  92.         if (LOWORD(wParam) == VK_TAB)
  93.         {
  94.             if (hwnd == hwndEnt[EntKeyField])
  95.             {
  96.                 SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
  97.                 SetFocus (hwndEnt[EntValueField]);
  98.             }
  99.             else
  100.                 SetFocus (hwndEnt[EntKeyField]);
  101.         }
  102.         if (LOWORD(wParam) == VK_RETURN)
  103.         {
  104.             if (hwnd == hwndEnt[EntKeyField])
  105.             {
  106.                 SendMessage (hwndEnt[EntValueField], WM_SETTEXT, 0, (long)"");
  107.                 SetFocus (hwndEnt[EntValueField]);
  108.             }
  109.             else
  110.             {
  111.                 AddProp ();
  112.                 SetFocus (g_qeglobals.d_hwndCamera);
  113.             }
  114.         }
  115.         break;
  116. //    case WM_NCHITTEST:
  117.     case WM_LBUTTONDOWN:
  118.         SetFocus (hwnd);
  119.         break;
  120.     }
  121.     return CallWindowProc (OldFieldWindowProc, hwnd, uMsg, wParam, lParam);
  122. }
  123.  
  124.  
  125. /*
  126. =========================
  127. EntityListWndProc
  128.  
  129. Just to handle enter...
  130. =========================
  131. */
  132. BOOL CALLBACK EntityListWndProc(
  133.     HWND hwnd,
  134.     UINT uMsg,
  135.     WPARAM wParam,
  136.     LPARAM lParam)
  137. {
  138.     switch (uMsg)
  139.     {
  140.     case WM_KEYDOWN:
  141.         if (LOWORD(wParam) == VK_RETURN)
  142.         {
  143.             SendMessage ( g_qeglobals.d_hwndEntity, 
  144.                           WM_COMMAND, 
  145.                           (LBN_DBLCLK<<16) + IDC_E_LIST, 
  146.                           0 );
  147.             return 0;
  148.         }
  149.         break;
  150.     }
  151.     return CallWindowProc (OldEntityListWindowProc, hwnd, uMsg, wParam, lParam);
  152. }
  153.  
  154.  
  155. /*
  156. ================
  157. GetEntityControls
  158.  
  159. Finds the controls from the dialog and
  160. moves them to the window
  161. ================
  162. */
  163. void GetEntityControls(HWND ghwndEntity)
  164. {
  165.     int i;
  166.  
  167.     for (i = 0; i < EntLast; i++)
  168.     {
  169.         if (i == EntList || i == EntProps || i == EntComment)
  170.             continue;
  171.         if (i == EntKeyField || i == EntValueField)
  172.             continue;
  173.         hwndEnt[i] = GetDlgItem(ghwndEntity, rgIds[i]);        
  174.         if (hwndEnt[i])
  175.             SetParent (hwndEnt[i], g_qeglobals.d_hwndEntity );
  176.     }
  177.  
  178.  
  179.     // SetParent apears to not modify some internal state
  180.     // on listboxes, so create it from scratch...
  181.  
  182.     hwndEnt[EntList] = CreateWindow ("listbox", NULL, 
  183.         LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_WANTKEYBOARDINPUT 
  184.         | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
  185.         5, 5, 180, 99,
  186.         g_qeglobals.d_hwndEntity,
  187.         (void *)IDC_E_LIST,
  188.         g_qeglobals.d_hInstance,
  189.         NULL);
  190.     if (!hwndEnt[EntList])
  191.         Error ("CreateWindow failed");
  192.  
  193.     hwndEnt[EntProps] = CreateWindow ("listbox", NULL, 
  194.         LBS_STANDARD | LBS_NOINTEGRALHEIGHT | LBS_USETABSTOPS
  195.         | WS_VSCROLL | WS_CHILD | WS_VISIBLE,
  196.         5, 100, 180, 99,
  197.         g_qeglobals.d_hwndEntity,
  198.         (void *)IDC_E_PROPS,
  199.         g_qeglobals.d_hInstance,
  200.         NULL);
  201.     if (!hwndEnt[EntProps])
  202.         Error ("CreateWindow failed");
  203.  
  204.     hwndEnt[EntComment] = CreateWindow ("edit", NULL, 
  205.         ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
  206.         5, 100, 180, 99,
  207.         g_qeglobals.d_hwndEntity,
  208.         (void *)IDC_E_COMMENT,
  209.         g_qeglobals.d_hInstance,
  210.         NULL);
  211.     if (!hwndEnt[EntComment])
  212.         Error ("CreateWindow failed");
  213.  
  214.     hwndEnt[EntKeyField] = CreateWindow ("edit", NULL, 
  215.         WS_CHILD | WS_VISIBLE | WS_BORDER,
  216.         5, 100, 180, 99,
  217.         g_qeglobals.d_hwndEntity,
  218.         (void *)IDC_E_KEY_FIELD,
  219.         g_qeglobals.d_hInstance,
  220.         NULL);
  221.     if (!hwndEnt[EntKeyField])
  222.         Error ("CreateWindow failed");
  223.  
  224.     hwndEnt[EntValueField] = CreateWindow ("edit", NULL, 
  225.         WS_CHILD | WS_VISIBLE | WS_BORDER,
  226.         5, 100, 180, 99,
  227.         g_qeglobals.d_hwndEntity,
  228.         (void *)IDC_E_VALUE_FIELD,
  229.         g_qeglobals.d_hInstance,
  230.         NULL);
  231.     if (!hwndEnt[EntValueField])
  232.         Error ("CreateWindow failed");
  233.  
  234.     g_qeglobals.d_hwndEdit = CreateWindow ("edit", NULL, 
  235.         ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER,
  236.         5, 100, 180, 99,
  237.         g_qeglobals.d_hwndEntity,
  238.         (void *)IDC_E_STATUS,
  239.         g_qeglobals.d_hInstance,
  240.         NULL);
  241.     if (!g_qeglobals.d_hwndEdit)
  242.         Error ("CreateWindow failed");
  243.  
  244.     g_qeglobals.d_hwndTexture = CreateTextureWindow ();
  245.  
  246. #if 0
  247.     for (i=0 ; i<12 ; i++)
  248.     {
  249.         hwndEnt[EntCheck1 + i] = CreateWindow ("button", NULL, 
  250.         BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
  251.         5, 100, 180, 99,
  252.         entwindow,
  253.         (void *)IDC_E_STATUS,
  254.         main_instance,
  255.         NULL);
  256.         if (!hwndEnt[EntCheck1 + i])
  257.             Error ("CreateWindow failed");
  258.     }
  259. #endif
  260. }
  261.  
  262.  
  263.  
  264. /*
  265. ===============================================================
  266.  
  267. ENTITY WINDOW
  268.  
  269. ===============================================================
  270. */
  271.  
  272.  
  273. void FillClassList (void)
  274. {
  275.     eclass_t    *pec;
  276.     int            iIndex;
  277.  
  278.     SendMessage(hwndEnt[EntList], LB_RESETCONTENT, 0 , 0);
  279.  
  280.     for (pec = eclass ; pec ; pec = pec->next)
  281.     {
  282.         iIndex = SendMessage(hwndEnt[EntList], LB_ADDSTRING, 0 , (LPARAM)pec->name);
  283.         SendMessage(hwndEnt[EntList], LB_SETITEMDATA, iIndex, (LPARAM)pec);
  284.     }    
  285.  
  286. }
  287.  
  288.  
  289. /*
  290. ==============
  291. WEnt_Create
  292. ==============
  293. */
  294. void WEnt_Create (HINSTANCE hInstance)
  295. {
  296.     WNDCLASS   wc;
  297.  
  298.     /* Register the camera class */
  299.     memset (&wc, 0, sizeof(wc));
  300.  
  301.     wc.style         = 0;
  302.     wc.lpfnWndProc   = (WNDPROC)EntityWndProc;
  303.     wc.cbClsExtra    = 0;
  304.     wc.cbWndExtra    = 0;
  305.     wc.hInstance     = hInstance;
  306.     wc.hIcon         = 0;
  307.     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
  308.     wc.hbrBackground = GetStockObject (LTGRAY_BRUSH);
  309.     wc.lpszMenuName  = NULL;
  310.     wc.lpszClassName = ENT_WINDOW_CLASS;
  311.  
  312.     if (!RegisterClass (&wc) )
  313.         Error ("RegisterClass: failed");
  314.  
  315.     g_qeglobals.d_hwndEntity = CreateWindow (ENT_WINDOW_CLASS ,
  316.         "Entity",
  317.         QE3_STYLE ,
  318.         20,
  319.         20,
  320.         100,
  321.         480,    // size
  322.  
  323.         g_qeglobals.d_hwndMain,    // parent
  324.         0,        // no menu
  325.         hInstance,
  326.         NULL);
  327.  
  328.     if (!g_qeglobals.d_hwndEntity )
  329.         Error ("Couldn't create Entity window");
  330. }
  331.  
  332. /*
  333. ==============
  334. CreateEntityWindow
  335. ==============
  336. */
  337. BOOL CreateEntityWindow(HINSTANCE hInstance)
  338. {
  339.     HWND hwndEntityPalette;
  340.  
  341.     inspector_mode = W_ENTITY;
  342.  
  343.     WEnt_Create (hInstance);
  344.  
  345.     hwndEntityPalette = CreateDialog(hInstance, (char *)IDD_ENTITY, g_qeglobals.d_hwndMain, (DLGPROC)NULL);
  346.     if (!hwndEntityPalette)
  347.         Error ("CreateDialog failed");
  348.  
  349.     GetEntityControls (hwndEntityPalette);
  350.     DestroyWindow (hwndEntityPalette);
  351.  
  352.     OldFieldWindowProc = (void *)GetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC);
  353.     SetWindowLong (hwndEnt[EntKeyField], GWL_WNDPROC, (long)FieldWndProc);
  354.     SetWindowLong (hwndEnt[EntValueField], GWL_WNDPROC, (long)FieldWndProc);
  355.  
  356.     OldEntityListWindowProc = (void *)GetWindowLong (hwndEnt[EntList], GWL_WNDPROC);
  357.     SetWindowLong (hwndEnt[EntList], GWL_WNDPROC, (long)EntityListWndProc);
  358.  
  359.     FillClassList ();
  360.  
  361.     LoadWindowState(g_qeglobals.d_hwndEntity, "EntityWindow");
  362.  
  363.     ShowWindow (g_qeglobals.d_hwndEntity, SW_SHOW);
  364.     SetInspectorMode (W_CONSOLE);
  365.  
  366.     return TRUE;
  367. }
  368.  
  369. /*
  370. ==============
  371. SetInspectorMode
  372. ==============
  373. */
  374. void SetInspectorMode(int iType)
  375. {
  376.     RECT rc;
  377.     HMENU hMenu = GetMenu( g_qeglobals.d_hwndMain );
  378.  
  379.     // Is the caller asking us to cycle to the next window?
  380.  
  381.     if (iType == -1)
  382.     {
  383.         if (inspector_mode == W_ENTITY)
  384.             iType = W_TEXTURE;
  385.         else if (inspector_mode == W_TEXTURE)
  386.             iType = W_CONSOLE;
  387.         else
  388.             iType = W_ENTITY;
  389.     }        
  390.  
  391.     inspector_mode = iType;
  392.     switch(iType)
  393.     {
  394.         
  395.     case W_ENTITY:
  396.         SetWindowText(g_qeglobals.d_hwndEntity, "Entity");
  397.         EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_ENABLED | MF_BYCOMMAND );
  398.         break;
  399.  
  400.     case W_TEXTURE:
  401. // title is set by textures.c        SetWindowText(g_qeglobals.d_hwndEntity, "Textures");
  402.         EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
  403.         break;
  404.  
  405.     case W_CONSOLE:
  406.         SetWindowText(g_qeglobals.d_hwndEntity, "Console");        
  407.         EnableMenuItem( hMenu, ID_MISC_SELECTENTITYCOLOR, MF_GRAYED | MF_DISABLED | MF_BYCOMMAND );
  408.         break;
  409.  
  410.     default:
  411.         break;
  412.     }
  413.  
  414.     GetWindowRect (g_qeglobals.d_hwndEntity, &rc);
  415.     SizeEntityDlg( rc.right - rc.left - 8, rc.bottom - rc.top - 32);
  416.  
  417.     RedrawWindow (g_qeglobals.d_hwndEntity, NULL, NULL, RDW_ERASE | RDW_INVALIDATE
  418.         | RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
  419.  
  420. //    InvalidateRect(entwindow, NULL, true);
  421. //    ShowWindow (entwindow, SW_SHOW);
  422. //    UpdateWindow (entwindow);
  423.  
  424.     SetWindowPos( g_qeglobals.d_hwndEntity, 
  425.                   HWND_TOP, 
  426.                   rc.left, rc.top, 
  427.                   rc.right - rc.left, rc.bottom - rc.top, 
  428.                   SWP_NOSIZE | SWP_NOMOVE );
  429. }
  430.  
  431.  
  432.  
  433.  
  434.  
  435. // SetKeyValuePairs
  436. //
  437. // Reset the key/value (aka property) listbox and fill it with the 
  438. // k/v pairs from the entity being edited.
  439. //
  440.  
  441. void SetKeyValuePairs (void)
  442. {
  443.     epair_t    *pep;
  444.     RECT    rc;
  445.     char    sz[4096];
  446.  
  447.     if (edit_entity == NULL)
  448.         return;
  449.  
  450.     // set key/value pair list
  451.  
  452.     GetWindowRect(hwndEnt[EntProps], &rc);
  453.     SendMessage(hwndEnt[EntProps], LB_SETCOLUMNWIDTH, (rc.right - rc.left)/2, 0);
  454.     SendMessage(hwndEnt[EntProps], LB_RESETCONTENT, 0, 0);
  455.  
  456.     // Walk through list and add pairs
  457.  
  458.     for (pep = edit_entity->epairs ; pep ; pep = pep->next)
  459.     {
  460.         // if the key is less than 8 chars, add a tab for alignment
  461.         if (strlen(pep->key) > 8)
  462.             sprintf (sz, "%s\t%s", pep->key, pep->value);
  463.         else
  464.             sprintf (sz, "%s\t\t%s", pep->key, pep->value);
  465.         SendMessage(hwndEnt[EntProps], LB_ADDSTRING, 0, (LPARAM)sz);
  466.     }
  467.  
  468. }
  469.  
  470. // SetSpawnFlags
  471. // 
  472. // Update the checkboxes to reflect the flag state of the entity
  473. //
  474. void SetSpawnFlags(void)
  475. {
  476.     int        f;
  477.     int        i;
  478.     int        v;
  479.  
  480.     f = atoi(ValueForKey (edit_entity, "spawnflags"));
  481.     for (i=0 ; i<12 ; i++)
  482.     {
  483.         v = !!(f&(1<<i));
  484.         SendMessage(hwndEnt[EntCheck1+i], BM_SETCHECK, v, 0);
  485.     }
  486. }
  487.  
  488.  
  489. // GetSpawnFlags
  490. // 
  491. // Update the entity flags to reflect the state of the checkboxes
  492. //
  493. void GetSpawnFlags(void)
  494. {
  495.     int        f;
  496.     int        i, v;
  497.     char    sz[32];
  498.  
  499.     f = 0;
  500.     for (i=0 ; i<12 ; i++)
  501.     {
  502.         v = SendMessage(hwndEnt[EntCheck1+i], BM_GETCHECK, 0, 0);
  503.         f |= v<<i;
  504.     }
  505.  
  506.     sprintf (sz, "%i", f);
  507.  
  508.     if (multiple_entities)
  509.     {
  510.         brush_t    *b;
  511.  
  512.         for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  513.             SetKeyValue(b->owner, "spawnflags", sz);
  514.     }
  515.     else
  516.         SetKeyValue (edit_entity, "spawnflags", sz);
  517.     SetKeyValuePairs ();
  518. }
  519.  
  520. // UpdateSel
  521. //
  522. // Update the listbox, checkboxes and k/v pairs to reflect the new selection
  523. //
  524.  
  525. BOOL UpdateSel(int iIndex, eclass_t *pec)
  526. {
  527.     int        i;
  528.     brush_t    *b;
  529.  
  530.     if (selected_brushes.next == &selected_brushes)
  531.     {
  532.         edit_entity = world_entity;
  533.         multiple_entities = false;
  534.     }
  535.     else
  536.     {
  537.         edit_entity = selected_brushes.next->owner;
  538.         for (b=selected_brushes.next->next ; b != &selected_brushes ; b=b->next)
  539.         {
  540.             if (b->owner != edit_entity)
  541.             {
  542.                 multiple_entities = true;
  543.                 break;
  544.             }
  545.         }
  546.     }
  547.  
  548.     if (iIndex != LB_ERR)
  549.         SendMessage(hwndEnt[EntList], LB_SETCURSEL, iIndex, 0);
  550.  
  551.     if (pec == NULL)
  552.         return TRUE;
  553.  
  554.     // Set up the description
  555.  
  556.     SendMessage(hwndEnt[EntComment], WM_SETTEXT, 0, 
  557.             (LPARAM)TranslateString(pec->comments));
  558.  
  559.     for (i=0 ; i<8 ; i++)
  560.     {
  561.         HWND hwnd = hwndEnt[EntCheck1+i];
  562.         if (pec->flagnames[i] && pec->flagnames[i][0] != 0)
  563.         {
  564.             EnableWindow(hwnd, TRUE);
  565.             SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)pec->flagnames[i]);
  566.         } else {
  567.  
  568.             // disable check box
  569.             SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)" ");
  570.             EnableWindow(hwnd, FALSE);
  571.         }
  572.     }
  573.  
  574.     SetSpawnFlags();
  575.     SetKeyValuePairs();
  576.     return TRUE;
  577. }
  578.  
  579. BOOL UpdateEntitySel(eclass_t *pec)
  580. {
  581.     int iIndex;
  582.     
  583.     iIndex = (int)SendMessage(hwndEnt[EntList], LB_FINDSTRINGEXACT, 
  584.             (WPARAM)-1, (LPARAM)pec->name);
  585.  
  586.     return UpdateSel(iIndex, pec);
  587. }
  588.  
  589. // CreateEntity
  590. //
  591. // Creates a new entity based on the currently selected brush and entity type.
  592. //
  593.  
  594. void CreateEntity(void)
  595. {
  596.     eclass_t *pecNew;
  597.     entity_t *petNew;
  598.     int i;
  599.     HWND hwnd;
  600.     char sz[1024];
  601.  
  602.     // check to make sure we have a brush
  603.  
  604.     if (selected_brushes.next == &selected_brushes)
  605.     {
  606.         MessageBox(g_qeglobals.d_hwndMain, "You must have a selected brush to create an entity"
  607.             , "info", 0);
  608.         return;
  609.     }
  610.  
  611.  
  612.     // find out what type of entity we are trying to create
  613.  
  614.     hwnd = hwndEnt[EntList];
  615.  
  616.     i = SendMessage(hwndEnt[EntList], LB_GETCURSEL, 0, 0);
  617.  
  618.     if (i < 0)
  619.     {
  620.         MessageBox(g_qeglobals.d_hwndMain, "You must have a selected class to create an entity"
  621.             , "info", 0);
  622.         return;
  623.     }
  624.  
  625.     SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);
  626.  
  627.     if (!stricmp(sz, "worldspawn"))
  628.     {
  629.         MessageBox(g_qeglobals.d_hwndMain, "Can't create an entity with worldspawn.", "info", 0);
  630.         return;
  631.     }
  632.  
  633.     pecNew = Eclass_ForName(sz, false);
  634.  
  635.     // create it
  636.  
  637.     petNew = Entity_Create(pecNew);
  638.  
  639.     if (petNew == NULL)
  640.     {
  641.         MessageBox(g_qeglobals.d_hwndMain, "Failed to create entity.", "info", 0);
  642.         return;
  643.     }
  644.  
  645.     if (selected_brushes.next == &selected_brushes)
  646.         edit_entity = world_entity;
  647.     else
  648.         edit_entity = selected_brushes.next->owner;
  649.  
  650.     SetKeyValuePairs();
  651.     Select_Deselect ();
  652.     Select_Brush (edit_entity->brushes.onext);
  653. }
  654.  
  655.  
  656.  
  657. /*
  658. ===============
  659. AddProp
  660.  
  661. ===============
  662. */
  663. void AddProp(void)
  664. {
  665.     char    key[4096];
  666.     char    value[4096];
  667.  
  668.     if (edit_entity == NULL)
  669.         return;
  670.  
  671.     // Get current selection text
  672.  
  673.     SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(key)-1, (LPARAM)key);    
  674.     SendMessage(hwndEnt[EntValueField], WM_GETTEXT, sizeof(value)-1, (LPARAM)value);    
  675.  
  676.     if (multiple_entities)
  677.     {
  678.         brush_t    *b;
  679.  
  680.         for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  681.             SetKeyValue(b->owner, key, value);
  682.     }
  683.     else
  684.         SetKeyValue(edit_entity, key, value);
  685.  
  686.     // refresh the prop listbox
  687.  
  688.     SetKeyValuePairs();    
  689. }
  690.  
  691. /*
  692. ===============
  693. DelProp
  694.  
  695. ===============
  696. */
  697. void DelProp(void)
  698. {
  699.     char    sz[4096];
  700.  
  701.     if (edit_entity == NULL)
  702.         return;
  703.  
  704.     // Get current selection text
  705.  
  706.     SendMessage(hwndEnt[EntKeyField], WM_GETTEXT, sizeof(sz)-1, (LPARAM)sz);    
  707.  
  708.     if (multiple_entities)
  709.     {
  710.         brush_t    *b;
  711.  
  712.         for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  713.             DeleteKey(b->owner, sz);
  714.     }
  715.     else
  716.         DeleteKey(edit_entity, sz);
  717.  
  718.     // refresh the prop listbox
  719.  
  720.     SetKeyValuePairs();    
  721. }
  722.  
  723. /*
  724. ===============
  725. EditProp
  726.  
  727. ===============
  728. */
  729. void EditProp(void)
  730. {
  731.     int i;
  732.     HWND hwnd;
  733.     char    sz[4096];
  734.     char    *val;
  735.  
  736.     if (edit_entity == NULL)
  737.         return;
  738.  
  739.     hwnd = hwndEnt[EntProps];
  740.  
  741.     // Get current selection text
  742.  
  743.     i = SendMessage(hwnd, LB_GETCURSEL, 0, 0);    
  744.  
  745.     if (i < 0)
  746.         return;
  747.  
  748.     SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)sz);    
  749.  
  750.     // strip it down to the key name
  751.  
  752.     for(i=0;sz[i] != '\t';i++)
  753.     ;
  754.  
  755.     sz[i] = '\0';
  756.  
  757.     val = sz + i + 1;
  758.     if (*val == '\t')
  759.         val++;
  760.  
  761.     SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)sz);    
  762.     SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)val);    
  763. }
  764.  
  765.  
  766. HDWP    defer;
  767. int        col;
  768. void MOVE(HWND e, int x, int y, int w, int h)
  769. {
  770. //    defer=DeferWindowPos(defer,e,HWND_TOP,col+(x),y,w,h,SWP_SHOWWINDOW);
  771. //    MoveWindow (e, col+x, y, w, h, FALSE);
  772.     SetWindowPos (e, HWND_TOP, col+x, y, w, h, 
  773.         SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOZORDER);
  774. }
  775.  
  776.  
  777. /*
  778. ===============
  779. SizeEnitityDlg
  780.  
  781. Positions all controls so that the active inspector
  782. is displayed correctly and the inactive ones are
  783. off the side
  784. ===============
  785. */
  786. void SizeEntityDlg(int iWidth, int iHeight)
  787. {
  788.     int y, x, xCheck, yCheck;
  789.     int i, iRow;
  790.     int    w, h;
  791.  
  792.     if (iWidth < 32 || iHeight < 32)
  793.         return;
  794.  
  795.     SendMessage( g_qeglobals.d_hwndEntity, WM_SETREDRAW, 0, 0);
  796.  
  797.     //==========================================
  798.  
  799.     //
  800.     // console
  801.     //
  802.  
  803.     if (inspector_mode == W_CONSOLE)
  804.         col = 0;
  805.     else
  806.         col = iWidth;
  807.  
  808.     MOVE(g_qeglobals.d_hwndEdit,    DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
  809.  
  810.     //==========================================
  811.  
  812.     //
  813.     // texture controls
  814.     //
  815.     if (inspector_mode == W_TEXTURE)
  816.         col = 0;
  817.     else
  818.         col = iWidth;
  819.  
  820.     MOVE(g_qeglobals.d_hwndTexture,    DlgXBorder, DlgYBorder, iWidth - (2 * DlgXBorder), iHeight - (2 * DlgYBorder) );
  821.  
  822.     //==========================================
  823.  
  824.     //
  825.     // entity controls
  826.     //
  827.     if (inspector_mode == W_ENTITY)
  828.         col = 0;
  829.     else
  830.         col = iWidth;
  831.  
  832.  
  833.     // top half includes the entity list (2/3) and the 
  834.     // comments (1/3) - 2 gaps, above and below.
  835.  
  836.     y = iHeight/2;
  837.     y -= 2 * DlgYBorder;
  838.     y = y / 3;
  839.     w = iWidth - (2 * DlgXBorder);
  840.     MOVE(hwndEnt[EntList], DlgXBorder, DlgYBorder, w, 2 * y);
  841.     
  842.     MOVE(hwndEnt[EntComment],
  843.         DlgXBorder, 2 * DlgYBorder + 2 * y, 
  844.         w, y - (2 * DlgYBorder));
  845.  
  846.     // bottom half includes flags (fixed), k/v pairs,
  847.     // and buttons (fixed).
  848.  
  849.     // xCheck = width of a single check box
  850.     // yCheck = distance from top of one check to the next
  851.  
  852.     xCheck = (iWidth - (2 * DlgXBorder)) / 3;
  853.     yCheck = 20;
  854.  
  855.     x = DlgXBorder;
  856.  
  857.     for (iRow = 0; iRow <= 12; iRow += 4)
  858.     {
  859.         y = iHeight/2;
  860.     
  861.         for (i = 0; i < 4; i++)
  862.         {
  863.             MOVE(hwndEnt[EntCheck1 + i + iRow],
  864.                 x, y, xCheck, yCheck);
  865.             y += yCheck;
  866.         }
  867.  
  868.         x += xCheck;
  869.     }
  870.  
  871.     //
  872.     // properties scroll box
  873.     //
  874.     y = iHeight/2 + 4 * yCheck;
  875.  
  876.     w = iWidth - (2 * DlgXBorder);
  877.     h = (iHeight - (yCheck * 5 + 2 * DlgYBorder) ) - y;
  878.  
  879.     MOVE(hwndEnt[EntProps], DlgXBorder, y, w, h);
  880.  
  881.     y += h + DlgYBorder;
  882.     
  883.     //
  884.     // key / value fields
  885.     //
  886.     w = iWidth-(DlgXBorder+45);
  887.     MOVE(hwndEnt[EntKeyLabel], DlgXBorder, y, 40, yCheck);
  888.     MOVE(hwndEnt[EntKeyField], DlgXBorder+40, y, w, yCheck);
  889.     y += yCheck;        
  890.  
  891.     MOVE(hwndEnt[EntValueLabel], DlgXBorder, y, 40, yCheck);
  892.     MOVE(hwndEnt[EntValueField], DlgXBorder+40, y, w, yCheck);
  893.     y += yCheck;        
  894.  
  895.     //
  896.     // angle check boxes
  897.     //
  898.     i = y;
  899.     x = DlgXBorder;
  900.  
  901.     xCheck = yCheck*2;
  902.  
  903.     MOVE(hwndEnt[EntDir135], x, y, xCheck, yCheck);
  904.     y += yCheck;        
  905.     
  906.     MOVE(hwndEnt[EntDir180], x, y, xCheck, yCheck);
  907.     y += yCheck;        
  908.     
  909.     MOVE(hwndEnt[EntDir225], x, y, xCheck, yCheck);
  910.  
  911.     y = i;
  912.     x += xCheck;
  913.  
  914.     
  915.     MOVE(hwndEnt[EntDir90], x, y, xCheck, yCheck);
  916.     y += yCheck;        
  917.     y += yCheck;        
  918.     
  919.     MOVE(hwndEnt[EntDir270], x, y, xCheck, yCheck);
  920.  
  921.     y = i;
  922.     x += xCheck;
  923.  
  924.     
  925.     MOVE(hwndEnt[EntDir45], x, y, xCheck, yCheck);
  926.     y += yCheck;        
  927.     
  928.     MOVE(hwndEnt[EntDir0], x, y, xCheck, yCheck);
  929.     y += yCheck;        
  930.     
  931.     MOVE(hwndEnt[EntDir315], x, y, xCheck, yCheck);
  932.  
  933.     y = i + yCheck/2;
  934.     x += xCheck + xCheck/2;
  935.  
  936.     
  937.     MOVE(hwndEnt[EntDirUp], x, y, xCheck, yCheck);
  938.     y += yCheck;        
  939.     
  940.     MOVE(hwndEnt[EntDirDown], x, y, xCheck, yCheck);
  941.  
  942.     y = i;
  943.     x += 1.5 * xCheck;
  944.     
  945.     MOVE(hwndEnt[EntDelProp], x, y, xCheck*2, yCheck);
  946.     y += yCheck;        
  947.  
  948.     SendMessage( g_qeglobals.d_hwndEntity, WM_SETREDRAW, 1, 0);
  949. //    InvalidateRect(entwindow, NULL, TRUE);
  950. }
  951.  
  952.  
  953. /*
  954. =========================
  955. EntityWndProc
  956. =========================
  957. */
  958. BOOL CALLBACK EntityWndProc(
  959.     HWND hwndDlg,    // handle to dialog box
  960.     UINT uMsg,        // message
  961.     WPARAM wParam,    // first message parameter
  962.     LPARAM lParam)    // second message parameter
  963. {
  964.     RECT    rc;
  965.  
  966.     GetClientRect(hwndDlg, &rc);
  967.  
  968.     switch (uMsg)
  969.     {
  970.     case WM_GETMINMAXINFO:
  971.         {
  972.             LPMINMAXINFO    lpmmi;
  973.  
  974.             lpmmi = (LPMINMAXINFO) lParam;
  975.             lpmmi->ptMinTrackSize.x = 320;
  976.             lpmmi->ptMinTrackSize.y = 500;
  977.         }
  978.         return 0;
  979.  
  980.     case WM_WINDOWPOSCHANGING:
  981.         {
  982.             LPWINDOWPOS    lpwp;
  983.             lpwp = (LPWINDOWPOS) lParam;
  984.  
  985.             DefWindowProc (hwndDlg, uMsg, wParam, lParam);
  986.  
  987.             lpwp->flags |= SWP_NOCOPYBITS;
  988.             SizeEntityDlg(lpwp->cx-8, lpwp->cy-32);
  989.             return 0;
  990.  
  991.         }
  992.         return 0;
  993.  
  994.  
  995.     case WM_COMMAND: 
  996.         switch (LOWORD(wParam)) { 
  997.         case IDC_E_DELPROP:
  998.             DelProp();
  999.             SetFocus (g_qeglobals.d_hwndCamera);
  1000.             break;
  1001.  
  1002.         case IDC_E_0:
  1003.             SetKeyValue (edit_entity, "angle", "0");
  1004.             SetFocus (g_qeglobals.d_hwndCamera);
  1005.             SetKeyValuePairs ();
  1006.             break;
  1007.         case IDC_E_45:
  1008.             SetKeyValue (edit_entity, "angle", "45");
  1009.             SetFocus (g_qeglobals.d_hwndCamera);
  1010.             SetKeyValuePairs ();
  1011.             break;
  1012.         case IDC_E_90:
  1013.             SetKeyValue (edit_entity, "angle", "90");
  1014.             SetFocus (g_qeglobals.d_hwndCamera);
  1015.             SetKeyValuePairs ();
  1016.             break;
  1017.         case IDC_E_135:
  1018.             SetKeyValue (edit_entity, "angle", "135");
  1019.             SetFocus (g_qeglobals.d_hwndCamera);
  1020.             SetKeyValuePairs ();
  1021.             break;
  1022.         case IDC_E_180:
  1023.             SetKeyValue (edit_entity, "angle", "180");
  1024.             SetFocus (g_qeglobals.d_hwndCamera);
  1025.             SetKeyValuePairs ();
  1026.             break;
  1027.         case IDC_E_225:
  1028.             SetKeyValue (edit_entity, "angle", "225");
  1029.             SetFocus (g_qeglobals.d_hwndCamera);
  1030.             SetKeyValuePairs ();
  1031.             break;
  1032.         case IDC_E_270:
  1033.             SetKeyValue (edit_entity, "angle", "270");
  1034.             SetFocus (g_qeglobals.d_hwndCamera);
  1035.             SetKeyValuePairs ();
  1036.             break;
  1037.         case IDC_E_315:
  1038.             SetKeyValue (edit_entity, "angle", "315");
  1039.             SetFocus (g_qeglobals.d_hwndCamera);
  1040.             SetKeyValuePairs ();
  1041.             break;
  1042.         case IDC_E_UP:
  1043.             SetKeyValue (edit_entity, "angle", "-1");
  1044.             SetFocus (g_qeglobals.d_hwndCamera);
  1045.             SetKeyValuePairs ();
  1046.             break;
  1047.         case IDC_E_DOWN:
  1048.             SetKeyValue (edit_entity, "angle", "-2");
  1049.             SetFocus (g_qeglobals.d_hwndCamera);
  1050.             SetKeyValuePairs ();
  1051.             break;
  1052.  
  1053.         case IDC_CHECK1:
  1054.         case IDC_CHECK2:
  1055.         case IDC_CHECK3:
  1056.         case IDC_CHECK4:
  1057.         case IDC_CHECK5:
  1058.         case IDC_CHECK6:
  1059.         case IDC_CHECK7:
  1060.         case IDC_CHECK8:
  1061.         case IDC_CHECK9:
  1062.         case IDC_CHECK10:
  1063.         case IDC_CHECK11:
  1064.         case IDC_CHECK12:
  1065.             GetSpawnFlags();
  1066.             SetFocus (g_qeglobals.d_hwndCamera);
  1067.             break;
  1068.  
  1069.  
  1070.         case IDC_E_PROPS: 
  1071.             switch (HIWORD(wParam))
  1072.             { 
  1073.             case LBN_SELCHANGE:
  1074.  
  1075.                 EditProp();
  1076.                 return TRUE; 
  1077.             }
  1078.             break;
  1079.  
  1080.         case IDC_E_LIST: 
  1081.        
  1082.             switch (HIWORD(wParam)) { 
  1083.             
  1084.             case LBN_SELCHANGE: 
  1085.             {
  1086.                 int iIndex;
  1087.                 eclass_t *pec;
  1088.                 
  1089.                 iIndex = SendMessage(hwndEnt[EntList], LB_GETCURSEL, 0, 0);    
  1090.                 pec = (eclass_t *)SendMessage(hwndEnt[EntList], LB_GETITEMDATA, 
  1091.                         iIndex, 0); 
  1092.             
  1093.                 UpdateSel(iIndex, pec);
  1094.  
  1095.                 return TRUE; 
  1096.                 break; 
  1097.             }
  1098.  
  1099.             case LBN_DBLCLK: 
  1100.                 CreateEntity ();
  1101.                 SetFocus (g_qeglobals.d_hwndCamera);
  1102.                 break; 
  1103.             } 
  1104.             break; 
  1105.  
  1106.  
  1107.             default: 
  1108.               return DefWindowProc( hwndDlg, uMsg, wParam, lParam ); 
  1109.         } 
  1110.  
  1111.         return 0;
  1112.     }
  1113.  
  1114.     return DefWindowProc (hwndDlg, uMsg, wParam, lParam);
  1115. }
  1116.